package event;



import org.objectweb.proactive.Body;
import org.objectweb.proactive.ProActive;
import org.objectweb.proactive.ext.migration.MigrationStrategyImpl;

import StreetController.StreetControllerAgent;
import Agents.agentFrame;
import Agents.AgentMessageReceiver;
import carGeneration.Vehicle;


public class Event implements java.io.Serializable {
	

	public Event siguiente;
	public Event anterior;
	public Event derecho;
	public Event izquierdo;
	public boolean eventoPotencial = false;
	private String name = "";
        public int desiredStatus;
	
	  private transient EventFrame myFrame;
	  private javax.swing.ImageIcon face;
	/**
	 *Identificador de tipo de evento
	 *
	 *0 CarArrival
	 *1	CarStop
	 *2	CarCross
	 *3 LightChange
	 *4 CarStart
	 *5 CarCreation
	 */
	protected	int typeEvent;

	/*
	 *identificador de objeto al que esta
	 *referenciado este evento
	 *recordando que cada evento modifica
	 *el estado de algun objeto en mi ambiente.
	 */
	protected Object objectId;   
	protected String type;

	protected double eventPosition ;
	/*Constructor del evento carArrival*/
	/**
	 * The event time of this event (when scheduled).
	 */	
	protected double eventTime = 0;
	/**
	 * Regrese el instante en el que se va a ejecutar este evento
	 */
        
        protected int lane;

        private boolean mostrarImagen = false;
    
	public void rebuild(){
		 Body body = ProActive.getBodyOnThis();
                 this.type= this.objectId + " T: "+this.evTime()+"Ty: "+this.getEventType();
	      if(mostrarImagen != false)
                 myFrame = new EventFrame(face, body.getNodeURL(), type);
	        //System.out.println("Penguin is here");
	        //sendMessageToControler("I just got in node " +
	          //  ProActive.getBodyOnThis().getNodeURL());
	    
                 try {
                     if(mostrarImagen==false)
	            Thread.sleep(100);
                     else
                         Thread.sleep(2000);
	        } catch (InterruptedException e) {
	        }
	}
	public void initialize(String s) {
        try {
            //With this we can load the image from the same location than
            //the classes
            ClassLoader cl = this.getClass().getClassLoader();
            //java.net.URL u = cl.getResource(
              //      "org/objectweb/proactive/examples/penguin/PenguinSmall.jpg");
            java.net.URL u = cl.getResource(s);
            face = new javax.swing.ImageIcon(u);
        } catch (Exception e) {
            e.printStackTrace();
        }
     
    }
	 public void clean() {
	        if (myFrame != null) {
	            myFrame.dispose();
	            myFrame = null;
	        }
	    }
	public  Object objectId(){
		return objectId;
	}

	/**
	 * Regrese el instante en el que se va a ejecutar este evento
	 */
	public double evTime(){
		return eventTime;
	}

	public double evPosition(){
		return eventPosition;
	}
	public int getEventType(){
		return	typeEvent;
	}

	public  void schedule(final double evTime, final int typeEvent,Object objectId,final double eventPosition,final int desiredStatus,int lane){
        
	this.typeEvent = typeEvent;
        this.objectId = objectId;
        this.eventPosition = eventPosition;
        this.eventTime = evTime;
        this.desiredStatus = desiredStatus;
        this.lane= lane;
       
        
    }
	public void setTime(double startTime){
		this.eventTime = startTime;
	}
	
	public String toString(){
		return "nombre evento:"+name;

	}
	public void putName(String name){
		this.name = name;
	}
	public String getName(){
		return name;
	}
        public int getDesiredStatus(){
            return this.desiredStatus;
        }
        public int getLane(){
            return this.lane;
        }

}
